package com.esig.demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JOptionPane {
    private JFrame mainFrame;
    private JLabel headerLabel;
    private JLabel statusLabel;
    private JPanel controlPanel;
    public JOptionPane(){
        prepareGUI();
    }
    public static void main(String[] args){
        JOptionPane JOptionPane = new JOptionPane();
        JOptionPane.showDialogDemo();
    }

    public static void showMessageDialog(Object o, String s, String 消息, int i) {
    }


    private void prepareGUI(){
        mainFrame = new JFrame("Java Swing Examples");
        mainFrame.setSize(400,400);
        mainFrame.setLayout(new GridLayout(3, 1));
        mainFrame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent windowEvent){
                System.exit(0);
            }
        });
        headerLabel = new JLabel("", JLabel.CENTER);
        statusLabel = new JLabel("",JLabel.CENTER);
        statusLabel.setSize(350,100);
        controlPanel = new JPanel();
        controlPanel.setLayout(new FlowLayout());
        mainFrame.add(headerLabel);
        mainFrame.add(controlPanel);
        mainFrame.add(statusLabel);
        mainFrame.setVisible(true);
    }
    private void showDialogDemo(){
        headerLabel.setText("Control in action: JOptionPane");
        JButton okButton = new JButton("OK");
        JButton javaButton = new JButton("Yes/No");
        JButton cancelButton = new JButton("Yes/No/Cancel");
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                javax.swing.JOptionPane.showMessageDialog(mainFrame, "Welcome to wenjiangs.com");
            }
        });
        javaButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int output = javax.swing.JOptionPane.showConfirmDialog(mainFrame
                        , "Click any button"
                        ,"wenjiangs.com"
                        , javax.swing.JOptionPane.YES_NO_OPTION);
                if(output == javax.swing.JOptionPane.YES_OPTION){
                    statusLabel.setText("Yes selected.");
                } else if(output == javax.swing.JOptionPane.NO_OPTION){
                    statusLabel.setText("No selected.");
                }
            }
        });
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int output = javax.swing.JOptionPane.showConfirmDialog(mainFrame
                        , "Click any button"
                        ,"wenjiangs.com"
                        , javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
                        javax.swing.JOptionPane.INFORMATION_MESSAGE);
                if(output == javax.swing.JOptionPane.YES_OPTION){
                    statusLabel.setText("Yes selected.");
                } else if(output == javax.swing.JOptionPane.NO_OPTION){
                    statusLabel.setText("No selected.");
                } else if(output == javax.swing.JOptionPane.CANCEL_OPTION){
                    statusLabel.setText("Cancel selected.");
                }
            }
        });
        controlPanel.add(okButton);
        controlPanel.add(javaButton);
        controlPanel.add(cancelButton);
        mainFrame.setVisible(true);
    }
}